/**
 * 响应拦截器
 * 统一接口使用 return 放回的数据信息格式
 */

import { NestInterceptor, CallHandler, ExecutionContext } from '@nestjs/common';
import { map } from 'rxjs/operators';
import { Observable } from 'rxjs';

interface data<T> {
  data: T;
}

export class ResIntercept<T> implements NestInterceptor {
  intercept(
    context: ExecutionContext,
    next: CallHandler<any>,
  ): Observable<any> | Promise<Observable<any>> {
    return next.handle().pipe(
      map((data, i) => {
        return {
          code: 0,
          data,
          msg: '获取成功',
        };
      }),
    );
  }
}
